<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>

<c:if test="${empty sessionScope.user or sessionScope.admin ne '1'}">
    <c:redirect url="error.jsp"/>
</c:if>

<!DOCTYPE html>
<html>
<head>
    <title>Service</title>
</head>
<body>

欢迎管理员 [${sessionScope.user}] 登录本系统 |
<a href="log-out">退出登录</a><br>

<jsp:useBean id="userDAO" class="org.example.week10.UserDAO" scope="page"/>
<c:set var="userList" value="${userDAO.searchAllUsers()}"/>

<table>
    <tr>
        <th>id</th>
        <th>用户名</th>
        <th>密码</th>
        <th>权限</th>
        <th>操作</th>
    </tr>

    <c:forEach items="${userList}" var="user">
        <tr>
            <td>${user.id}</td>
            <td>${user.name}</td>
            <td>${user.pwd}</td>

            <c:choose>
                <c:when test="${user.priv eq 1}">
                    <td>管理员</td>
                    <td>管理员</td>
                </c:when>
                <c:when test="${user.priv eq 2}">
                    <td>普通用户</td>
                    <td><a href='user-manage?id=${user.id}'>账户停用</a></td>
                </c:when>
                <c:when test="${user.priv == 3}">
                    <td>游客</td>
                    <td><a href='user-manage?id=${user.id}'>审核通过</a></td>
                </c:when>
            </c:choose>
        </tr>
    </c:forEach>
</table>

</body>
</html>